﻿<UserControl x:Class="PocoGen.Gui.Presentation.Views.TableView"
             x:ClassModifier="internal"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:controls="clr-namespace:PocoGen.Gui.Presentation.Controls"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <DataTemplate x:Key="StretchedHeaderTemplate">
            <ContentPresenter Content="{TemplateBinding Content}" Loaded="ContentPresenter_Loaded" />
        </DataTemplate>
    </UserControl.Resources>
    <Border Style="{StaticResource ContentBorder}" UseLayoutRounding="True">
        <Expander HeaderTemplate="{StaticResource StretchedHeaderTemplate}" IsExpanded="{Binding IsExpanded}">
            <Expander.Header>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <Image Source="{Binding IsView,Converter={StaticResource TableImageConverter}}" VerticalAlignment="Center" Margin="0,0,5,0" />

                    <CheckBox Grid.Column="1" IsChecked="{Binding Include}" ToolTip="Include table" VerticalContentAlignment="Center" />

                    <controls:ObjectDbTextEdit Grid.Column="2" DbElementName="{Binding TableName}" CodeElementName="{Binding ClassName}" Margin="3,0,0,0" />
                </Grid>
            </Expander.Header>

            <ListBox ItemsSource="{Binding Columns}" Margin="18,10,0,0" ItemContainerStyle="{StaticResource ListBoxWithNoSelection}" Background="Transparent" BorderThickness="0" MaxHeight="{Binding ActualHeight, Converter={StaticResource HeightConverter}, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" />
        </Expander>
    </Border>
</UserControl>
